﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
using System.Diagnostics;
using System.Windows.Media;

namespace UML_Creator.Model
{
    public class DiamondConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int ax = int.Parse(values[0].ToString());
            int ay = int.Parse(values[1].ToString());
            int ax_ = int.Parse(values[2].ToString());
            int ay_ = int.Parse(values[3].ToString());

            int bx = int.Parse(values[4].ToString());
            int by = int.Parse(values[5].ToString());
            int bx_ = int.Parse(values[6].ToString());
            int by_ = int.Parse(values[7].ToString());


            Point aBase = new Point(ax + ax_ / 2, ay + ay_ / 2);
            Point bBase = new Point(bx + bx_ / 2, by + by_ / 2);


            double angle = Math.Atan2(bBase.X - aBase.X, bBase.Y - aBase.Y) * 180.0 / Math.PI;

            PointCollection pc = new PointCollection(4);
            //Direction right
            if (135 > angle && angle > 45)
            {
                pc.Add(new Point(bx, by+by_/2));
                pc.Add(new Point(bx-8, by + (by_ / 2)-8));
                pc.Add(new Point(bx-16, by + (by_ / 2)));
                pc.Add(new Point(bx-8, by + (by_ / 2)+8));
            }

            //Direction left (Right inversed)
            if (-45 > angle && angle > -135)
            {
                pc.Add(new Point(bx+bx_, by + by_ / 2));
                pc.Add(new Point(bx + bx_ + 8, by + (by_ / 2) - 8));
                pc.Add(new Point(bx + bx_ + 16, by + (by_ / 2)));
                pc.Add(new Point(bx + bx_ + 8, by + (by_ / 2) + 8));
            }

            //Direction up
            if (-135 > angle && angle > -180 || 135 < angle && angle < 180)
            {
                pc.Add(new Point(bx + bx_/2, by + by_));
                pc.Add(new Point(8+bx + bx_ / 2, by + by_+8));
                pc.Add(new Point(bx + bx_ / 2, by + by_+16));
                pc.Add(new Point(-8+bx + bx_ / 2, by + by_+8));
            }

            //Direction down (Up inversed)
            if (45 > angle && angle > -45)
            {
                pc.Add(new Point(bx + bx_ / 2, by ));
                pc.Add(new Point(8 + bx + bx_ / 2, by + - 8));
                pc.Add(new Point(bx + bx_ / 2, by  - 16));
                pc.Add(new Point(-8 + bx + bx_ / 2, by  -8));
            }
            
       

            return pc;

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
